require('module-alias/register')
var {captchaExpiryTime} = require('@root/config.js')
var svgCaptcha = require('svg-captcha');
var { redisClient, setValue, getValue } = require('@utils/Redis')
var { v4  } = require ('uuid');



var captcha = function (req, res, next) {
    var hasUuid = !!req.cookies.uuid
    var key=hasUuid?req.cookies.uuid:v4()
    var captchaModel = svgCaptcha.create();
	setValue(key,captchaModel.text, captchaExpiryTime)
	res.status(200).send({data:captchaModel.data,key:key,time:captchaExpiryTime})
}
module.exports = { captcha };